package com.chen.manager.controller;

import com.chen.manager.service.CategoryService;
import com.chen.model.entity.product.Category;
import com.chen.model.vo.common.Result;
import com.chen.model.vo.common.ResultCodeEnum;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author cgj
 * @date 3/1/25 3:12 PM
 */
@RestController
@RequestMapping("/admin/product/category")
///admin/product/category/getCategoryListByParentId/0"
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 用户上传excel
     * @param file
     * @return
     */
    @PostMapping("uploadExcel")
    public Result uploadExcel(MultipartFile file){
        categoryService.uploadExcel(file);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 用户导出excel
     * @param response
     */
    @GetMapping("/excelExport")
    //不需要返回值, 由response设置
    public void excelExport(HttpServletResponse response){
        categoryService.excelExport(response);
    }
    /**
     * 根据pid查询 下属子级分类
     * @param pid
     * @return
     */
    @GetMapping("/getCategoryListByParentId/{pid}")
    public Result<List<Category>> getCategoryListByParentId(@PathVariable Long pid){
        List<Category> categoryList=categoryService.getCategoryListByParentId(pid);
        return  Result.build(categoryList,ResultCodeEnum.SUCCESS);
    }


}
